﻿@inherits VaultElement
@using System.IO
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.AspNetCore.Razor.TagHelpers
@using Microsoft.Extensions.Localization

<div class="vault-feedback mb-2 d-flex align-items-center">
    <Icon Class=@($"vault-feedback-icon icon me-2 {GetClass()}") Symbol="@GetSymbol()"></Icon>
    <span class="vault-feedback-content flex-grow">
				@if (Html is not null)
        {
            @((MarkupString)Html)
        }
        else if (Text is not null)
        {
            @Text
        }
            </span>
</div>

@code {
    public Feedback()
    {
    }

    public Feedback(LocalizedString str, FeedbackType state)
    {
        this.State = state;
        this.Text = str.ToString();
    }

    public Feedback(LocalizedHtmlString str, FeedbackType state)
    {
        this.State = state;
        var txt = new StringWriter();
        str.WriteTo(txt, NullHtmlEncoder.Default);
        this.Html = txt.ToString();
    }



    public FeedbackType State { get; set; }

    public string GetClass()
        => State switch
        {
            FeedbackType.Loading => "icon-dots feedback-icon-loading",
            FeedbackType.Success => "icon-checkmark feedback-icon-success",
            FeedbackType.Failed => "icon-cross feedback-icon-failed",
            _ => ""
        };

    public string GetSymbol()
        => State switch
        {
            FeedbackType.Loading => "dots",
            FeedbackType.Success => "checkmark",
            FeedbackType.Failed => "cross",
            _ => ""
        };

    public string Html { get; set; }
    public string Text { get; set; }
}
